﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace AimGameLibrary.GameObject
{
    public class GameGravity : BaseGameObject
    {
        float Strength;

        public override void LoadData(Identification getdata, int IndexData, NodeData node)
        {
            Strength = (float)getdata.Items.GetValue(IndexData + 1);
            int count = (int)getdata.Items.GetValue(IndexData + 2);
            if (count > 0)
            {
                String Temp = (String)getdata.Items.GetValue(IndexData + 3);
                for (int i = 0; i < count; i++)
                    Listnameparent.Add(Script.GetName(Temp, count, i));
            }
        }

        public override void UpdateGameTime(GameTime gametime)
        {
            base.UpdateGameTime(gametime);

            GravityUpdate();
        }

        public override void UpdateTime(TimeSpan timespan)
        {
            base.UpdateTime(timespan);

            
            GravityUpdate();
        }

        public void GravityUpdate()
        {
            foreach (BaseGameObject basegameobject in Listparent)
            {
                if (basegameobject.GetType() == typeof(GameBody))
                {
                    GameBody body = (GameBody)basegameobject;
                    
                        //body.UpdateGravity(Strength);
                    //if (body.myDirectioninCollision == DirectionInCollision.None)
                    //{
                        Body tempStrength = new Body(0, 0, 0, 0, this.Strength);
                        Body tempForceStep1 = body.MybodY;
                        Body tempForceStep2 = Body.AddBody(tempForceStep1, tempStrength);
                        body.MybodY = tempForceStep2;
                        Body tempForceStep3 = body.MybodY;
                        Body tempForceStep4 = new Body(0, tempForceStep3.MyForce, 0, 0, 0);
                        Body tempForceStep5 = Body.AddBody(tempForceStep3, tempForceStep4);
                        body.MybodY = tempForceStep5;
                    //}
                    
                }
            }

        }

        
    }
}
